﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using UmlDesigner.Model;

namespace UmlDesigner.Gui
{
    internal partial class TypeSelectionForm : Form
    {
        internal TypeSelectionForm()
        {
            InitializeComponent();
            Icon = Properties.Resources.ApplicationIcon;

            foreach (string line in Properties.Resources.StandardTypes.Split('\n'))
            {
                if (line.Trim().Length > 0)
                {
                    ListViewItem item = new ListViewItem(typeListView.Groups[0]);
                    item.Text = line.Trim();
                    typeListView.Items.Add(item);
                }
            }

            foreach (Document doc in Project.Instance.Documents)
            {
                foreach (ItemWidget itemWidget in doc.items)
                {
                    if (itemWidget.IsClass())
                    {
                        ClassWidget classWidget = (ClassWidget)itemWidget;

                        ListViewItem item = new ListViewItem(typeListView.Groups[1]);
                        item.Text = classWidget.GetClassName();
                        typeListView.Items.Add(item);
                    }
                }
            }

        }

        private void typeListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (typeListView.SelectedItems.Count == 0)
            {
                okButton.Enabled = false;
            }
            else
            {
                okButton.Enabled = true;
                selectedType = typeListView.SelectedItems[0].Text;
            }
        }

        private void typeListView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (typeListView.SelectedItems.Count != 0)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }

        internal string selectedType;
    }
}
